package com.xb.loan.cashier.biz.pay.alipay;

import java.util.HashMap;
import java.util.Map;

/**
 * 支付宝错误码
 */
public enum AlipayErrorCode {
    /****wap支付状态码****/
    /****业务错误码****/
    payIllegalSign(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "ILLEGAL_SIGN", "签名不正确"),
    payIllegalDynMd5Key(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "ILLEGAL_DYN_MD5_KEY", "动态密钥信息错误"),
    payIllegalEncrypt(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "ILLEGAL_ENCRYPT", "加密不正确"),
    payIllegalArgument(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "ILLEGAL_ARGUMENT", "参数不正确"),
    payIllegalService(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "ILLEGAL_SERVICE", "Service参数不正确"),
    payIllgalPartner(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "ILLEGAL_PARTNER", "合作伙伴ID不正确"),
    payIllegalExterface(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "ILLEGAL_EXTERFACE", "接口配置不正确"),
    payIllegalPartnerExterface(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "ILLEGAL_PARTNER_EXTERFACE", "合作伙伴接口信息不正确"),
    payIllegalSecurityProfile(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "ILLEGAL_SECURITY_PROFILE", "未找到匹配的密钥配置"),
    payIllegalAgent(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "ILLEGAL_AGENT", "代理ID不正确"),
    /****系统错误码****/
    paySystemError(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "SYSTEM_ERROR", "支付宝系统错误"),
    paySessionTimeout(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "SESSION_TIMEOUT", "session超时"),
    payIllegalTargetService(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "ILLEGAL_TARGET_SERVICE", "错误的target_service"),
    payIllegalAccessSwitchSystem(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "ILLEGAL_ACCESS_SWITCH_SYSTEM", "partner不允许访问该类型的系统"),
    payIllegalSwitchSystem(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "ILLEGAL_SWITCH_SYSTEM", "切换系统异常"),
    /****交易状态码****/
    payWaitBuyerPay(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "WAIT_BUYER_PAY", "等待买家付款"),
    payTradeClosed(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "TRADE_CLOSED", "关闭的交易"),
    payTradeSuccess(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "TRADE_SUCCESS", "交易成功"),
    payTradePending(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "TRADE_PENDING", "等待卖家收款"),
    payTradeFinished(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "TRADE_FINISHED", "交易成功且结束"),
    
    /****web支付状态码****/
    /****交易状态码****/
    payWaitBuyerPayWeb(AlipayPaymentForCharge.MODULE_WEB_DIRECT_PAY, "WAIT_BUYER_PAY", "等待买家付款"),
    payTradeClosedWeb(AlipayPaymentForCharge.MODULE_WEB_DIRECT_PAY, "TRADE_CLOSED", "关闭的交易"),
    payTradeSuccessWeb(AlipayPaymentForCharge.MODULE_WEB_DIRECT_PAY, "TRADE_SUCCESS", "交易成功"),
    payTradePendingWeb(AlipayPaymentForCharge.MODULE_WEB_DIRECT_PAY, "TRADE_PENDING", "等待卖家收款"),
    payTradeFinishedWeb(AlipayPaymentForCharge.MODULE_WEB_DIRECT_PAY, "TRADE_FINISHED", "交易成功且结束"),
    
    /****单笔查询状态码****/
    /****业务错误码****/
    queryTradeNotExist(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "TRADE_NOT_EXIST", "交易不存在"),
    queryIllegalSign(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_SIGN", "签名不正确"),
    queryIllegalDynMd5Key(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_DYN_MD5_KEY", "动态密钥信息错误"),
    queryIllegalEncrypt(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_ENCRYPT", "加密不正确"),
    queryIllegalArgument(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_ARGUMENT", "参数不正确"),
    queryIllegalService(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_SERVICE", "Service参数不正确"),
    queryIllegalUser(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_USER", "客户ID不正确"),
    queryIllegalPartner(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_PARTNER", "商户ID不正确"),
    queryIllegalExterface(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_EXTERFACE", "接口配置不正确"),
    queryIllegalPartnerExterface(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_PARTNER_EXTERFACE", "商户接口信息不正确"),
    queryIllegalSecurityProfile(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_SECURITY_PROFILE", "未找到匹配的密钥配置"),
    queryIllegalAgent(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_AGENT", "代理ID不正确"),
    queryIllegalSignType(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_SIGN_TYPE", "签名类型不正确"),
    queryIllegalCharset(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_CHARSET", "字符集不合法"),
    queryIllegalClientIp(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_CLIENT_IP", "客户端IP地址无权访问服务"),
    queryHasNoPrivilege(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "HAS_NO_PRIVILEGE", "无权访问"),
    queryIllegalDigestType(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_DIGEST_TYPE", "摘要类型不正确"),
    queryIllegalDigest(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_DIGEST", "文件摘要不正确"),
    queryIllegalFileFormat(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_FILE_FORMAT", "文件格式不正确"),
    queryIllegalEncoding(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_ENCODING", "不支持该编码类型"),
    queryExterfaceIsClosed(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "EXTERFACE_IS_CLOSED", "接口已关闭"),
    queryIllegalRequestReferer(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_REQUEST_REFERER", "防钓鱼检查不支持该请求来源"),
    queryIllegalAntiPhishingKey(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_ANTI_PHISHING_KEY", "防钓鱼检查非法时间戳参数"),
    queryAntiPhishingKeyTimeout(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ANTI_PHISHING_KEY_TIMEOUT", "防钓鱼检查时间戳超时"),
    queryIllegalExterInvokeIp(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_EXTER_INVOKE_IP", "防钓鱼检查非法调用IP"),
    /****系统错误码****/
    querySystemError(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "SYSTEM_ERROR", "支付宝系统错误"),
    querySessionTimeout(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "SESSION_TIMEOUT", "session超时"),
    queryIllegalTargetService(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_TARGET_SERVICE", "错误的target_service"),
    queryIllegalAccessSwitchSystem(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_ACCESS_SWITCH_SYSTEM", "partner不允许访问该类型的系统"),
    queryIllegalSwitchSystem(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ILLEGAL_SWITCH_SYSTEM", "切换系统异常"),
    /****交易状态码****/
    queryWaitBuyerPay(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "WAIT_BUYER_PAY", "等待买家付款"),
    queryWaitSellerSendGoods(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "WAIT_SELLER_SEND_GOODS", "等待卖家发货"),
    queryWaitBuyerConfirmGoods(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "WAIT_BUYER_CONFIRM_GOODS", "等待买家确认"),
    queryTradeFinished(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "TRADE_FINISHED", "交易成功结束"),
    queryTradeClosed(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "TRADE_CLOSED", "交易中途关闭（已结束，未成功完成）"),
    queryWaitSysConfirmPay(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "WAIT_SYS_CONFIRM_PAY", "支付宝确认买家银行汇款中，暂勿发货"),
    queryWaitSysPaySeller(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "WAIT_SYS_PAY_SELLER", "买家确认收货"),
    queryTradeRefuse(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "TRADE_REFUSE", "立即支付交易拒绝"),
    queryTradeRefuseDealing(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "TRADE_REFUSE_DEALING", "立即支付交易拒绝中"),
    queryTradeCancel(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "TRADE_CANCEL", "立即支付交易取消"),
    queryTradePending(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "TRADE_PENDING", "等待卖家收款"),
    queryTradeSuccess(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "TRADE_SUCCESS", "支付成功"),
    queryBuyerPreAuth(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "BUYER_PRE_AUTH", "买家已付款（语音支付）"),
    queryCodWaitSellerSendGoods(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "COD_WAIT_SELLER_SEND_GOODS", "等待卖家发货（货到付款）"),
    queryCodWaitbuyerPay(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "COD_WAIT_BUYER_PAY", "等待买家签收付款（货到付款）"),
    queryCodWaitSysPaySeller(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "COD_WAIT_SYS_PAY_SELLER", "签收成功等待系统打款给卖家（货到付款）"),
    /****交易附加状态码****/
    queryZhifubaoConfirm(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ZHIFUBAO_CONFIRM", "客服代买家确认收货"),
    queryZhifubaoCancelFp(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "ZHIFUBAO_CANCEL_FP", "客服代付款方取消快速支付"),
    queryDaemonConfirmCancelPreAuth(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "DAEMON_CONFIRM_CANCEL_PRE_AUTH", "超时程序取消预授权"),
    queryDaemonConfirmClose(AlipayPayment.MODULE_SINGLE_TRADE_QUERY, "DAEMON_CONFIRM_CLOSE", "超时程序因买家不付款关闭交易");
    
    private String module;      // 模块
    private String errorCode;   // 错误码
    private String errorMsg;    // 错误描述
    private AlipayErrorCode(String module, String errorCode, String errorMsg){
        this.errorCode = errorCode;
        this.errorMsg = errorMsg;
        this.module = module;
    }
    public String getErrorCode() {
        return errorCode;
    }
    public String getErrorMsg() {
        return errorMsg;
    }
    public String getModule() {
        return module;
    }
    public static AlipayErrorCode getError(String module, String errorCode){
        Map<String, AlipayErrorCode> map = codeBeanMap.get(module);
        if(map==null){
            return null;
        }
        return map.get(errorCode);
    }
    public static String getErrorMsg(String module, String errorCode){
        Map<String, AlipayErrorCode> map = codeBeanMap.get(module);
        if(map==null){
            return null;
        }
        AlipayErrorCode code = map.get(errorCode);
        if(code==null){
            return null;
        }
        return code.getErrorMsg();
    }
    private static Map<String, Map<String, AlipayErrorCode>> codeBeanMap = new HashMap<String, Map<String, AlipayErrorCode>>();
    static{
        for(AlipayErrorCode obj : AlipayErrorCode.values()){
            String module = obj.getModule();
            Map<String, AlipayErrorCode> beanMap = codeBeanMap.get(module);
            if(beanMap==null){
                beanMap = new HashMap<String, AlipayErrorCode>();
                codeBeanMap.put(module, beanMap);
            }
            beanMap.put(obj.getErrorCode(), obj);
        }
    }
    
    public static void main(String[] args) {
        System.out.println(AlipayErrorCode.getErrorMsg(AlipayPaymentForCharge.MODULE_WAP_DIRECT_PAY, "ILLEGAL_SIGN"));
    }
}
